#pragma once

#include "eventfd_types.h"
#include <boost/asio.hpp>
#include <atomic>
#include <string>
#include <chrono>

using namespace boost::asio;

/**
 * EventFD 发送器基类
 */
class EventFdSender {
public:
    explicit EventFdSender(io_context& io, const std::string& identifier = "eventfd_transfer");
    virtual ~EventFdSender();
    
    /**
     * 启动发送器
     */
    virtual bool start() = 0;
    
    /**
     * 停止发送器
     */
    virtual void stop();
    
    /**
     * 异步发送EventFD
     */
    virtual void async_send_eventfd(int eventfd, TransferCallback callback) = 0;
    
    /**
     * 设置EventFD发送回调
     */
    void set_transfer_callback(TransferCallback callback);

    /**
     * 设置连接状态回调
     */
    void set_connection_callback(ConnectionCallback callback);
    
    /**
     * 设置超时参数
     */
    void set_timeouts(std::chrono::milliseconds connect_timeout,
                     std::chrono::milliseconds retry_interval);
    
    /**
     * 获取运行状态
     */
    bool is_running() const;

protected:
    io_context& io_;
    std::string identifier_;
    std::atomic<bool> running_;
    std::atomic<int> retry_count_;
    int max_retry_count_;
    
    std::chrono::milliseconds connect_timeout_{5000};
    std::chrono::milliseconds retry_interval_{3000};
    
    
    TransferCallback transfer_callback_;
    ConnectionCallback connection_callback_;
};
